package middleware

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"pkg"
	"types"
)

func MiddleWare() gin.HandlerFunc {
	return func(c *gin.Context) {
		Token := c.PostForm("token")
		if Token == "" {
			c.JSON(http.StatusBadRequest, types.Router{
				Code:     -1,
				Msg:      "token为空",
				Database: nil,
			})
			return
			c.Next()
		}
		pa, err := pkg.WareJwtToken("", Token)
		if err != nil {
			c.JSON(http.StatusBadRequest, types.Router{
				Code:     -1,
				Msg:      "token解析失败",
				Database: nil,
			})
			return
			c.Next()
		}
		c.Set(Token, pa)
	}
}
